package com.itqf.serilaize;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * projectName: springmvcgp8
 *
 * @author: 赵伟风
 * time: 2021/8/6 14:50
 * description:
 */
public class SexSerilaizer extends JsonSerializer<Integer> {
    /**
     * Method that can be called to ask implementation to serialize
     * values of type this serializer handles.
     *
     * @param value       Value to serialize; can <b>not</b> be null.
     * @param gen         Generator used to output resulting Json content
     * @param serializers Provider that can be used to get serializers for
     */
    @Override
    public void serialize(Integer value, JsonGenerator gen, SerializerProvider serializers) throws IOException {

        //value = 0 /1;
        String sex = "男";

        if (value == 0) {
            sex = "女";
        }

        gen.writeString(sex);
    }
}
